import gtk
import gobject


def KeymapMixinMeta(name, bases, env):
    __gsignals__ = {
        "key_press_event" : "override",
        "key_release_event" : "override",
    }
    base = bases[0]
    def do_key_press_event(self, arg):
        if base.do_key_press_event(self, arg):
            return True
        if self.owner:
            return self.owner.do_key_press_event(arg)
        return False
    def do_key_release_event(self, arg):
        if base.do_key_release_event(self, arg):
            return True
        if self.owner:
            return self.owner.do_key_release_event(arg)
        return False
    env["owner"] = None
    env["__gsignals__"]  = __gsignals__
    env["do_key_press_event"] = do_key_press_event
    env["do_key_release_event"] = do_key_release_event
    meta = type(base)
    return meta(name, bases, env)


class Window(gtk.Window):
    __metaclass__ = KeymapMixinMeta
    
    def __init__(self, title, child):
        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
        self.set_title(title)
        self.connect("destroy", gtk.main_quit)
        #self.add(child)

class Frame(gtk.Frame):
    __metaclass__ = KeymapMixinMeta

class Scrolled(gtk.ScrolledWindow):
    __metaclass__ = KeymapMixinMeta

class TreeBox(gtk.TreeView):
    __metaclass__ = KeymapMixinMeta

class TextLine(gtk.Entry):
    __metaclass__ = KeymapMixinMeta

class TextBox(gtk.TextView):
    __metaclass__ = KeymapMixinMeta

class Button(gtk.Button):
    __metaclass__ = KeymapMixinMeta
    def __init__(self, text, callback = None):
        gtk.Button.__init__(self, text)
        if callback:
            self.connect("clicked", callback)

class Label(gtk.Label):
    __metaclass__ = KeymapMixinMeta






#w = Window("hello", None)
#w.show()
#gtk.main()


